import {ElMessage} from 'element-plus'
import getColumns from './printTableColumns'
/**
 * 配置说明
 * DrawerHeader_title：标题
 * DrawerInfo_ulProps：信息配置props
 * H4_stepTip_open: 温馨提示显示状态
 * CardList_prop：卡牌列表prop配置列
 * ElButton_printCardTag_open：打印本订单的卡牌标签按钮显示状态
 * ElButton_prevOrder_open：上一个订单按钮显示状态
 * ElButton_nextOrder_open：下一个订单按钮显示状态
 * ElButton_submitReview_open：提交复核按钮显示状态
 * ElButton_printCardOrder_open：打印全部送卡订单按钮显示状态
 * ElButton_goBack_open：返回按钮显示状态
 * ElButton_printPutStoreOrder_open：打印全部入库单显示状态
 * ElButton_vipPrintPutStoreOrder_open：打印全部vip入库单显示状态
 * ElButton_nextStep_open：下一步显示状态
 * ElButton_batchPutStore_open：批量确认入库显示状态
 * ElButton_batchReturnCard_open：批量回寄卡牌显示状态
 * ElCheckbox_checkAll_open：全选显示状态
 * WriteCardLogisticsDialog_open：填写卡牌回寄信息弹窗显示状态
 * ReturnCardLogisticsDialog_open：已回寄卡牌物流回显信息弹窗显示状态
 * PrintCardOrders_open：打印卡牌信息弹窗显示状态
 * PrintCardOrders_bindProps：打印卡牌信息弹窗配置化数据
 */
export const configMap = new Map([
  ['firstReview', {
    DrawerHeader_title: '已发货订单详情页',
    DrawerInfo_ulProps: ['logistics', 'sendCard', 'orderList'],
    H4_stepTip_open: true,
    CardList_prop: 9,
    ElButton_printCardTag_open: true,
    ElButton_prevOrder_open: true,
    ElButton_nextOrder_open: true,
    ElButton_submitReview_open: true,
    PrintCardOrders_open: true,
    PrintCardOrders_bindProps: {
      headerTitle: '开箱初审--打印送卡订单',
      title: '送卡订单',
      infoProps: ['totalAmount', 'firstReviewResult', 'firstReviewInfo'],
      tableColumns: getColumns('firstReview'),
      prop: 'firstReview'
    }
  }],
  ['review', {
    DrawerHeader_title: '待复核订单详情页',
    DrawerInfo_ulProps: ['logistics', 'sendCard', 'firstTrial', 'orderList'],
    CardList_prop: 10,
    ElButton_printCardTag_open: true,
    ElButton_printCardOrder_open: true,
    ElButton_goBack_open: true,
    PrintCardOrders_open: true,
    PrintCardOrders_bindProps: {
      headerTitle: '待复核--打印送卡订单',
      title: '送卡订单',
      infoProps: ['totalAmount', 'firstReviewResult', 'firstReviewInfo'],
      tableColumns: getColumns('review'),
      prop: 'review'
    }
  }],
  ['putStore', {
    DrawerHeader_title: '待入库订单详情页',
    DrawerInfo_ulProps: ['logistics', 'sendCard', 'review', 'orderList'],
    CardList_prop: 11,
    ElButton_printCardTag_open: true,
    ElButton_printPutStoreOrder_open: true,
    ElButton_batchPutStore_open: true,
    ElButton_batchReturnCard_open: true,
    ElButton_nextStep_open: true,
    ElCheckbox_checkAll_open: true,
    WriteCardLogisticsDialog_open: true,
    PrintCardOrders_open: true,
    PrintCardOrders_bindProps: {
      headerTitle: '打印入库单',
      title: '入库单',
      infoProps: ['totalAmount', 'reviewResult', 'reviewInfo'],
      tableColumns: getColumns('putStore'),
      prop: 'putStore'
    }
  }],
  ['sendCard', {
    DrawerHeader_title: '待回寄卡牌订单详情页',
    DrawerInfo_ulProps: ['logistics', 'sendCard', 'review', 'enter', 'orderList'],
    CardList_prop: 12,
    ElButton_batchReturnCard_open: true,
    ElCheckbox_checkAll_open: true,
    ElButton_goBack_open: true
  }],
  ['allPutStore', {
    DrawerHeader_title: '已入库订单详情页',
    DrawerInfo_ulProps: ['logistics', 'sendCard', 'review', 'enter', 'orderList'],
    CardList_prop: 13,
    ElButton_goBack_open: true,
    ReturnCardLogisticsDialog_open: true
  }]
])

// 校验评级类型、分数、评级号码、原卡扫描、贴纸
const cardTrialRules = {
  rating: '请选择评级类型',
  score: '请选择分数',
  ratingNo: '请输入评级号码',
  'frontImage.url': '请上传卡牌正面扫描',
  'backImage.url': '请上传卡牌背面扫描',
  'stickerPhoto.url': '请上传贴标正面拍照'
}

export const cardTrialValidate = (row) => {
  for (const k of Object.keys(cardTrialRules)) {
    // 多层级取值
    const keys = k.split('.')
    const value = keys.reduce((prev, key) => {
      return prev[key]
    }, row)
    console.log(value, '1')
    if(!value) {
      // 生成未填内容提示
      ElMessage({
        message: cardTrialRules[k],
        type: 'error',
        center: true
      })
      return false
    }
  }
  // 特殊校验 如：当初审不通过时，须选择不通过原因
  if (row.firstReview === 2 && !row.firstReason) {
    ElMessage({
      message: '请选择不通过原因',
      type: 'error',
      center: true
    })
    return false
  }
  return true
}
